|
|
|
|
|
|
|
Sometimes you may need to store and retrieve information but not need the power of a database (not to mention the extra coding, configuration, and support files that go along with it). In these cases, a text file may be just the thing you need. In this section, you will learn about a simple type of file: a free-form, sequential text file. Sequential means that the file is accessed one byte after the other in sequence, rather than jumping to a specific location. Free form means that the file has no predefined structure; it is entirely up to the programmer. |
|
|
|
|
|
|
|
|
Suppose you have a form in which the user must choose salespersons from a list, as shown in Figure 21.3. Your mission is to load the names of each salesperson into a list box so that the user can select these names. You could just put a bunch of AddItem statements in the Form_Load event. However, doing so would be a poor solution because you have hard-coded information in the program. Any time the sales force changed, the program would have to be recompiled. A better solution is to use a text file with the salespersons' names in it. The program then reads the names from the text file and populates the list box. |
|
|
|
|
|
|
|
|
Figure 21.3
The list box is populated
with the contents of a text file. |
|
|
|
|
|
|
|
|
To create the file itself, you can use a text editor such as Notepad, placing each salesperson's name on a separate line, as shown in Figure 21.4. |
|
|
|
|
|
|
|
|
Figure 21.4
Data stored in sequential
text files can be easily edited. |
|
|
|
|
|